package com.bajiao.admin.controller.order;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bajiao.common.api.vo.Result;
import com.bajiao.entity.order.RefundCouponOrder;
import com.bajiao.entity.order.RefundOrder;
import com.bajiao.service.order.RefundCouponOrderService;
import com.bajiao.vo.order.RefundCouponOrderAdmin;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import com.bajiao.admin.base.AdminBaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @Description: 优惠券退款单
 * @Author: FanJq
 * @Date: 2024-12-14
 * @Version: V1.0
 */
@Slf4j
@Api(tags = "优惠券退款单")
@RestController
@RequestMapping("/refund/coupon")
public class RefundCouponOrderController extends AdminBaseController<RefundCouponOrder, RefundCouponOrderService> {
    @Autowired
    private RefundCouponOrderService refundCouponOrderService;

    /**
     * @return
     * @description: 分页列表查询
     * @author: FanJq
     * @date: 2024-12-14
     */
    @ApiOperation(value = "优惠券退款单-分页列表查询", notes = "优惠券退款单-分页列表查询")
    @GetMapping(value = "/list")
    public Result<?> queryPageList(String orderNo, String keywords, String title, Integer status, String createTimeBegin, String createTimeEnd) {
        startPage();
        List<RefundCouponOrderAdmin> resultList = refundCouponOrderService.getAdminList(orderNo, keywords, title, status, createTimeBegin, createTimeEnd);
        return Result.ok(getDataTable(resultList));
    }

    /**
     * @param refundCouponOrder
     * @return
     * @description: 添加
     * @author: FanJq
     * @date: 2024-12-14
     */
    @ApiOperation(value = "优惠券退款单-添加", notes = "优惠券退款单-添加")
    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody RefundCouponOrder refundCouponOrder) {
        refundCouponOrderService.save(refundCouponOrder);
        return Result.ok("添加成功！");
    }

    /**
     * @param refundCouponOrder
     * @return
     * @description: 编辑
     * @author: FanJq
     * @date: 2024-12-14
     */
    @ApiOperation(value = "优惠券退款单-编辑", notes = "优惠券退款单-编辑")
    @PutMapping(value = "/edit")
    public Result<?> edit(@RequestBody RefundCouponOrder refundCouponOrder) {
        refundCouponOrderService.updateById(refundCouponOrder);
        return Result.ok("编辑成功!");
    }

    @ApiOperation(value = "退款单-审批", notes = "退款单-审批")
    @PutMapping(value = "/audit")
    public Result<?> audit(@RequestBody RefundCouponOrder request) {
        RefundCouponOrder refundOrder = refundCouponOrderService.getById(request.getId());
		refundCouponOrderService.approve(refundOrder, request.getStatus());
        return Result.ok(request.getStatus() == 1 ? "已退款" : "已驳回");
    }

    /**
     * @param id
     * @return
     * @description: 通过id删除
     * @author: FanJq
     * @date: 2024-12-14
     */
    @ApiOperation(value = "优惠券退款单-通过id删除", notes = "优惠券退款单-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
        refundCouponOrderService.removeById(id);
        return Result.ok("删除成功!");
    }

    /**
     * @param ids
     * @return
     * @description: 批量删除
     * @author: FanJq
     * @date: 2024-12-14
     */
    @ApiOperation(value = "优惠券退款单-批量删除", notes = "优惠券退款单-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.refundCouponOrderService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.ok("批量删除成功！");
    }

    /**
     * @param id
     * @return
     * @description: 通过id查询
     * @author: FanJq
     * @date: 2024-12-14
     */
    @ApiOperation(value = "优惠券退款单-通过id查询", notes = "优惠券退款单-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
        RefundCouponOrder refundCouponOrder = refundCouponOrderService.getById(id);
        return Result.ok(refundCouponOrder);
    }

    /**
     * @param request
     * @param refundCouponOrder
     * @description: 导出excel
     * @author: FanJq
     * @date: 2024-12-14
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, RefundCouponOrder refundCouponOrder) {
        return super.exportXls(request, refundCouponOrder, RefundCouponOrder.class, "优惠券退款单");
    }

    /**
     * @param request
     * @param response
     * @return
     * @description: 通过excel导入数据
     * @author: FanJq
     * @date: 2024-12-14
     */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, RefundCouponOrder.class);
    }

}
